﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using MongoDB.Bson.Serialization.Attributes;

namespace ifunction.Fiddler.Model
{
    /// <summary>
    /// Class RequestPackage.
    /// </summary>
    [DataContract]
    public class RequestLog
    {
        /// <summary>
        /// Gets or sets the key.
        /// </summary>
        /// <value>The key.</value>
        [DataMember]
        [BsonId]
        public Guid Key { get; set; }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>The name.</value>
        [DataMember]
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the package key.
        /// </summary>
        /// <value>The package key.</value>
        [DataMember]
        public Guid PackageKey { get; set; }

        /// <summary>
        /// Gets or sets the target URL.
        /// </summary>
        /// <value>The target URL.</value>
        [DataMember]
        public string TargetUrl { get; set; }

        /// <summary>
        /// Gets or sets the created stamp.
        /// </summary>
        /// <value>The created stamp.</value>
        [DataMember]
        public DateTime CreatedStamp { get; set; }

        /// <summary>
        /// Gets or sets the response code.
        /// </summary>
        /// <value>The response code.</value>
        [DataMember]
        public string ResponseCode { get; set; }

        /// <summary>
        /// Automatics the log.
        /// </summary>
        /// <returns>System.String.</returns>
        public string ToLog()
        {
            return string.Format(@"{0}
{1} [{2}]
Uri: {3}
Response: {4}
",
              this.CreatedStamp.ToString("yyyy-MM-dd HH:mm:ss.fff"),
              this.Name.GetStringValue(),
              this.Key.ToString(),
              this.TargetUrl.GetStringValue(),
              this.ResponseCode.GetStringValue()
                );
        }
    }
}
